/*ui.stars.min
* jQuery UI Stars v2.1.1
* http://plugins.jquery.com/project/Star_Rating_widget
*
* Copyright (c) 2009 Orkan (orkans@gmail.com)
* Dual licensed under the MIT and GPL licenses.
* http://docs.jquery.com/License
*
* $Rev: 114 $
* $Date:: 2009-06-12 #$
* $Build: 32 (2009-06-12)
*
* Depends:
*  ui.core.js
*
*/
(function(A) { A.widget("ui.stars", { _init: function() { var B = this, E = this.options, F = 0; E.isSelect = E.inputType == "select"; this.$form = A(this.element).closest("form"); this.$selec = E.isSelect ? A("select", this.element) : null; this.$rboxs = E.isSelect ? A("option", this.$selec) : A(":radio", this.element); this.$stars = this.$rboxs.map(function(I) { var J = { value: this.value, title: (E.isSelect ? this.text : this.title) || this.value, isDefault: (E.isSelect && this.defaultSelected) || this.defaultChecked }; if (I == 0) { E.split = typeof E.split != "number" ? 0 : E.split; E.val2id = []; E.id2val = []; E.id2title = []; E.name = E.isSelect ? B.$selec.get(0).name : this.name; E.disabled = E.disabled || (E.isSelect ? A(B.$selec).attr("disabled") : A(this).attr("disabled")) } if (J.value == E.cancelValue) { E.cancelTitle = J.title; return null } E.val2id[J.value] = F; E.id2val[F] = J.value; E.id2title[F] = J.title; if (J.isDefault) { E.checked = F; E.value = E.defaultValue = J.value; E.title = J.title } var H = A("<div/>").addClass(E.starClass); var K = A("<a/>").attr("title", E.showTitles ? J.title : "").text(J.value); if (E.split) { var G = (F % E.split); var L = Math.floor(E.starWidth / E.split); H.width(L); K.css("margin-left", "-" + (G * L) + "px") } F++; return H.append(K).get(0) }); E.items = F; E.isSelect ? this.$selec.remove() : this.$rboxs.remove(); this.$cancel = A("<div/>").addClass(E.cancelClass).append(A("<a/>").attr("title", E.showTitles ? E.cancelTitle : "").text(E.cancelValue)); E.cancelShow &= !E.disabled && !E.oneVoteOnly; E.cancelShow && this.element.append(this.$cancel); this.element.append(this.$stars); if (E.checked === undefined) { E.checked = -1; E.value = E.defaultValue = E.cancelValue; E.title = "" } this.$value = A('<input type="hidden" name="' + E.name + '" value="' + E.value + '" />'); this.element.append(this.$value); this.$stars.bind("click.stars", function(H) { if (!E.forceSelect && E.disabled) { return false } var G = B.$stars.index(this); E.checked = G; E.value = E.id2val[G]; E.title = E.id2title[G]; B.$value.attr({ disabled: E.disabled ? "disabled" : "", value: E.value }); C(G, false); B._disableCancel(); !E.forceSelect && B.callback(H, "star") }).bind("mouseover.stars", function() { if (E.disabled) { return false } var G = B.$stars.index(this); C(G, true) }).bind("mouseout.stars", function() { if (E.disabled) { return false } C(B.options.checked, false) }); this.$cancel.bind("click.stars", function(G) { if (!E.forceSelect && (E.disabled || E.value == E.cancelValue)) { return false } E.checked = -1; E.value = E.cancelValue; E.title = ""; B.$value.val(E.value).attr({ disabled: "disabled" }); D(); B._disableCancel(); !E.forceSelect && B.callback(G, "cancel") }).bind("mouseover.stars", function() { if (B._disableCancel()) { return false } B.$cancel.addClass(E.cancelHoverClass); D(); B._showCap(E.cancelTitle) }).bind("mouseout.stars", function() { if (B._disableCancel()) { return false } B.$cancel.removeClass(E.cancelHoverClass); B.$stars.triggerHandler("mouseout.stars") }); this.$form.bind("reset.stars", function() { !E.disabled && B.select(E.defaultValue) }); A(window).unload(function() { B.$cancel.unbind(".stars"); B.$stars.unbind(".stars"); B.$form.unbind(".stars"); B.$selec = B.$rboxs = B.$stars = B.$value = B.$cancel = B.$form = null }); function C(G, I) { if (G != -1) { var J = I ? E.starHoverClass : E.starOnClass; var H = I ? E.starOnClass : E.starHoverClass; B.$stars.eq(G).prevAll("." + E.starClass).andSelf().removeClass(H).addClass(J); B.$stars.eq(G).nextAll("." + E.starClass).removeClass(E.starHoverClass + " " + E.starOnClass); B._showCap(E.id2title[G]) } else { D() } } function D() { B.$stars.removeClass(E.starOnClass + " " + E.starHoverClass); B._showCap("") } this.select(E.value); E.disabled && this.disable() }, _disableCancel: function() { var C = this.options, B = C.disabled || C.oneVoteOnly || (C.value == C.cancelValue); if (B) { this.$cancel.removeClass(C.cancelHoverClass).addClass(C.cancelDisabledClass) } else { this.$cancel.removeClass(C.cancelDisabledClass) } this.$cancel.css("opacity", B ? 0.5 : 1); return B }, _disableAll: function() { var B = this.options; this._disableCancel(); if (B.disabled) { this.$stars.filter("div").addClass(B.starDisabledClass) } else { this.$stars.filter("div").removeClass(B.starDisabledClass) } }, _showCap: function(B) { var C = this.options; if (C.captionEl) { C.captionEl.text(B) } }, value: function() { return this.options.value }, select: function(D) { var C = this.options, B = (D == C.cancelValue) ? this.$cancel : this.$stars.eq(C.val2id[D]); C.forceSelect = true; B.triggerHandler("click.stars"); C.forceSelect = false }, selectID: function(D) { var C = this.options, B = (D == -1) ? this.$cancel : this.$stars.eq(D); C.forceSelect = true; B.triggerHandler("click.stars"); C.forceSelect = false }, enable: function() { this.options.disabled = false; this._disableAll() }, disable: function() { this.options.disabled = true; this._disableAll() }, destroy: function() { this.options.isSelect ? this.$selec.appendTo(this.element) : this.$rboxs.appendTo(this.element); this.$form.unbind(".stars"); this.$cancel.unbind(".stars").remove(); this.$stars.unbind(".stars").remove(); this.$value.remove(); this.element.unbind(".stars").removeData("stars") }, callback: function(C, B) { var D = this.options; D.callback && D.callback(this, B, D.value, C); D.oneVoteOnly && !D.disabled && this.disable() } }); A.extend(A.ui.stars, { version: "2.1.1", getter: "value", defaults: { inputType: "radio", split: 0, disabled: false, cancelTitle: "Cancel Rating", cancelValue: 0, cancelShow: true, oneVoteOnly: false, showTitles: false, captionEl: null, callback: null, starWidth: 16, cancelClass: "ui-stars-cancel", starClass: "ui-stars-star", starOnClass: "ui-stars-star-on", starHoverClass: "ui-stars-star-hover", starDisabledClass: "ui-stars-star-disabled", cancelHoverClass: "ui-stars-cancel-hover", cancelDisabledClass: "ui-stars-cancel-disabled"} }) })(jQuery);